/// 返回代码
class ReturnCodes {
  final int value;

  const ReturnCodes._(this.value);

  ///支付成功
  static const ECR_SUCCESS = ReturnCodes._(0);

  ///交易失败
  static const ECR_FAILED = ReturnCodes._(-1);

  ///未发送或值错误
  static const ECR_TRANSACTIONID_INVALID = ReturnCodes._(-2);

  ///未找到事务。此代码通常发送到 Inquiry 请求，这意味着您可以重新启动事务。
  static const ECR_TRANSACTION_NOT_FOUND = ReturnCodes._(-3);

  ///交易被拒绝
  static const ECR_TRANSACTION_DECLINE = ReturnCodes._(-4);

  ///交易已取消
  static const ECR_TRANSACTION_ALREADY_VOIDED = ReturnCodes._(-5);

  ///参数无效，请检查是否存在或格式正确
  static const ECR_PARAMETER_INVALID = ReturnCodes._(-6);

  ///错误，用户未授权。
  static const ECR_UNAUTHORIZED = ReturnCodes._(-7);

  ///错误，不允许
  static const ECR_NOT_ALLOWED = ReturnCodes._(-8);

  ///GP tom 中需要用户的输入。
  static const ECR_WRONG_STATUS = ReturnCodes._(-9);

  // 所有可能值
  static const values = [
    ECR_SUCCESS,
    ECR_FAILED,
    ECR_TRANSACTIONID_INVALID,
    ECR_TRANSACTION_NOT_FOUND,
    ECR_TRANSACTION_DECLINE,
    ECR_TRANSACTION_ALREADY_VOIDED,
    ECR_PARAMETER_INVALID,
    ECR_NOT_ALLOWED,
    ECR_WRONG_STATUS,
  ];
}

extension ReturnCodesExtension on ReturnCodes {
  static const _nameMap = {
    ReturnCodes.ECR_SUCCESS: 'ECR_SUCCESS',
    ReturnCodes.ECR_FAILED: 'ECR_FAILED',
    ReturnCodes.ECR_TRANSACTIONID_INVALID: 'ECR_TRANSACTIONID_INVALID',
    ReturnCodes.ECR_TRANSACTION_NOT_FOUND: 'ECR_TRANSACTION_NOT_FOUND',
    ReturnCodes.ECR_TRANSACTION_DECLINE: 'ECR_TRANSACTION_DECLINE',
    ReturnCodes.ECR_TRANSACTION_ALREADY_VOIDED:
        'ECR_TRANSACTION_ALREADY_VOIDED',
    ReturnCodes.ECR_PARAMETER_INVALID: 'ECR_PARAMETER_INVALID',
    ReturnCodes.ECR_UNAUTHORIZED: 'ECR_UNAUTHORIZED',
    ReturnCodes.ECR_NOT_ALLOWED: 'ECR_NOT_ALLOWED',
    ReturnCodes.ECR_WRONG_STATUS: 'ECR_WRONG_STATUS',
  };

  String? get name => _nameMap[this];
}
